package com.zhiying.zfb;

import java.util.List;

import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter{

	private List<ZfbInfo> mList;
	
	private Context mContext;
	
	public ListViewAdapter(Context mContext, List<ZfbInfo> mList) {
		this.mContext = mContext;
		this.mList = mList;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public ZfbInfo getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ZfbInfo zfbInfo = getItem(position);
		ZfbInfoItem zfbInfoItem = new ZfbInfoItem();
		if(convertView == null) {
			View v = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
			zfbInfoItem.riqi_item = (TextView) v.findViewById(R.id.riqi_item);
			zfbInfoItem.benjin_item = (TextView) v.findViewById(R.id.benjin_item);
			zfbInfoItem.shengyutianshu_item = (TextView) v.findViewById(R.id.shengyutianshu_item);
			zfbInfoItem.yuqililv_item = (TextView) v.findViewById(R.id.yuqililv_item);
			zfbInfoItem.bianxianlilv_item = (TextView)v.findViewById(R.id.bianxianlilv_item);
			zfbInfoItem.kebianxian_item = (TextView) v.findViewById(R.id.kebianxian_item);
			zfbInfoItem.jinglirun_item = (TextView) v.findViewById(R.id.jinglirun_item);
			v.setTag(zfbInfoItem);
			convertView = v;
		} else {
			zfbInfoItem = (ZfbInfoItem) convertView.getTag();
		}
		zfbInfoItem.riqi_item.setText(zfbInfo.getRiqi());
		zfbInfoItem.benjin_item.setText(zfbInfo.getBenjin());
		zfbInfoItem.shengyutianshu_item.setText(zfbInfo.getShengyutianshu());
		zfbInfoItem.yuqililv_item.setText(zfbInfo.getYuqililv());
		zfbInfoItem.bianxianlilv_item.setText(zfbInfo.getBianxianlilv());
		zfbInfoItem.kebianxian_item.setText((int)Float.parseFloat(zfbInfo.getKebianxian())+"");
		zfbInfoItem.jinglirun_item.setText((int)Float.parseFloat(zfbInfo.getJinglirun())+"");
		return convertView;
	}
	
	private class ZfbInfoItem {
		TextView riqi_item;
		TextView benjin_item;
		TextView shengyutianshu_item;
		TextView yuqililv_item;
		TextView bianxianlilv_item;
		TextView kebianxian_item;
		TextView jinglirun_item;
	}

}
